package com.code.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.code.dao.MxMapper;
import com.code.dao.HtMapper;
import com.code.entity.PageResult;
import com.code.entity.QueryPageBean;
import com.code.pojo.Mx;
import com.code.pojo.Ht;
import com.code.service.HtService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Service
public class HtServiceImpl implements HtService {

    @Autowired
    HtMapper htMapper;
    @Autowired
    MxMapper productMapper;


    @Override
    public PageResult<Ht> findPage(QueryPageBean queryPageBean) {
     PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Ht> htList = htMapper.findLike(queryPageBean);
        PageInfo<Ht> pageInfo = new PageInfo<>(htList);
        PageResult<Ht> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;

    }
//    @Override
//    public PageResult<Ht> findPage(Ht ht) {
//     PageHelper.startPage(ht.getPage(),ht.getSize());
//        List<Ht> htList = htMapper.findLike(ht);
//        PageInfo<Ht> pageInfo = new PageInfo<>(htList);
//        PageResult<Ht> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
//        return result;
//    }



    @Override
    public Ht findById(Integer id) {
        return htMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(Ht ht) {
        htMapper.insert(ht);
    }

    @Override
    public void update(Ht ht) {
        htMapper.updateByPrimaryKeySelective(ht);
    }

    @Override
    public void delete(Integer id) {
        htMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Mx> findMx() {
        return productMapper.selectAll();
    }


//   统计用注解写Sql语句 字段名称为 name  value
    @Override
    public List<Map> tongji() {
        return htMapper.tongji();
    }

//    @Override
//    public List<Map> twobzt() {
//        return htMapper.twobzt();
////        return null;
//    }

    @Override
    public PageResult<Ht> findPageNo(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Ht> htList = htMapper.findPageNo(queryPageBean);
        PageInfo<Ht> pageInfo = new PageInfo<>(htList);
        PageResult<Ht> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;
    }

    @Override
    public void editState(Integer id) {
        Ht ht = htMapper.selectByPrimaryKey(id);
        ht.setState(2);
        htMapper.updateByPrimaryKeySelective(ht);
    }
}
